/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.CommandListener;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.TextBox;
import javax.microedition.midlet.*;

/**
 * @author Abahe
 */
public class HelloWorld extends MIDlet implements CommandListener {

    private Display display;
    private TextBox tb;
    private Command cmdHello;
    private Command cmdKeluar;

    public HelloWorld() {
        display = Display.getDisplay(this);
    }

    public void startApp() {
        tb = new TextBox("Masukan Nama", "", 256, 0);

        cmdHello = new Command("Hello", Command.OK, 1);
        cmdKeluar = new Command("Keluar", Command.EXIT, 1);

        tb.addCommand(cmdHello);
        tb.addCommand(cmdKeluar);

        tb.setCommandListener(this);
        display.setCurrent(tb);
    }

    public void pauseApp() {
    }

    public void destroyApp(boolean unconditional) {
    }

    public void commandAction(Command c, Displayable d) {
        if (c == cmdHello) {
            if (!tb.getString().equals("")) {
                tb.setString("Hello " + tb.getString() + "!");
            }
        } else if (c == cmdKeluar) {
            destroyApp(false);
            notifyDestroyed();
        }
    }
}
